import userManagementService from "../service/userManagement";
import vipCard from "../store/vipCard";
import userManagement from "../store/userManagement";
import vipCardLevel from "../store/vipCardLevel";
import coachStore from "../store/coachStore";
const store = vipCard();
const userStore = userManagement();
const vipCardLevelStore = vipCardLevel();
const coach = coachStore();
// 会员卡信息分页
function page_vipCard(cardType: number, limit: number, name: string, page: number): any {
    userManagementService.pageVipCard(cardType, limit, name, page).then((res: any) => {
        console.log(res.data.data);
        store.setPageVipCard(res.data.data)
    })
}

// 搜索会员卡信息byid
function search_vipCardById(id: number) {
    userManagementService.searchVipCardById(id).then((res: any) => {
        // console.log(123);
        // console.log(res.data.data);
        store.setSearchVipCardListById(res.data.data)
    })
}

// 用户分页信息
function pageUser(createTime: string, limit: string, name: string, page: number, phone: string) {//会员列表数据渲染
    userManagementService.getUserPageList(createTime, limit, name, page, phone).then((res: any) => {
        // console.log("请求成功",res.data.data);
        userStore.setUserData(res.data)
    })
}

// 根据id查询用户信息
function userById(id: number) {
    userManagementService.userById(id).then((res: any) => {
        // console.log("请求成功id",res.data.data);
        userStore.setUserDataById(res.data.data)
    })
}

// 根据用户id查询用户会员卡信息
function getUserCardInfoByUserId(userId:number){
        // console.log("请求id",userId);
    userManagementService.getUserCardInfoByUserId(userId).then((res:any)=>{
        // console.log(res.data);
        userStore.setSearchVipCardById(res.data.data)
    })
}

// 查询用户所有收获地址
function searchAddressByUserId(userId:number){
    console.log("DIZHI请求id",userId);
    userManagementService.searchAddressByUserId(userId).then((res:any)=>{
        // console.log(res.data.data);
        userStore.setSearchVipCardById(res.data.data)
    })
}


// 查询会员卡等级
function getVipLevel(){
    userManagementService.pageVipLevel().then((res:any)=>{
        // console.log("hooks请求成功", res.data.data);
        vipCardLevelStore.setPageVipCardLevel(res.data.data)

    })
}

// 根据id查找积分规则信息
function integralRuleById(id:number){
    userManagementService.integralRuleById(id).then((res:any)=>{
        // console.log("hooks请求成功", res.data.data);
        vipCardLevelStore.setIntegralRuleById(res.data.data)     
    })
}

// 跟新积分规则
function integralRuleUpdate(buy:number,continuousDay:number,deductions:number,deductionsPercentage:number,extra:number,id:number,punchRewards:number){
    userManagementService.integralRuleUpdate(buy,continuousDay,deductions,deductionsPercentage,extra,id,punchRewards).then((res)=>{
        // console.log("更改成功",res.data);
    })
}

// 添加会员卡等级
function addVipLevel(defaultUse:number,discount:string,integralRequirement:number,name:string){
    userManagementService.addVipLevel(defaultUse,discount,integralRequirement,name).then((res:any)=>{
        console.log("是否使用：", defaultUse);
        getVipLevel()
    })
}

// 搜索会员卡信息byid
function searchVipLevelById(id:number){
    userManagementService.searchVipLevelById(id).then((res:any)=>{
        res.data.data.defaultUse  = res.data.data.defaultUse==0?"是":"否"
        console.log("searchVipLevelById",res.data.data.defaultUse);
        vipCardLevelStore.setVipCardLevelById(res.data.data)
    })
}

//删除会员卡等级
function delVipLevelById(id:number){
    userManagementService.delVipLevel(id).then((res:any)=>{
        console.log("删除：",res.data.data);
        getVipLevel()
    })
}

// 编辑会员卡等级信息
function changeVipLevel(id:number,name:string,defaultUse:number,integralRequirement:number,discount:string,createTime:string){
    userManagementService.changeVipLevel(id,name,defaultUse,integralRequirement,discount,createTime).then((res:any)=>{
        console.log("更新数据",res.data.data);
        getVipLevel()
        
    })
}

// 查询会员卡等级
function userVipCardPageList(cardStatus:number,limit:number,page:number,queryName:string){
    userManagementService.userVipCardPageList(cardStatus,limit,page,queryName).then((res:any)=>{
        console.log(res.data.data);
        store.setUserVipCardPageList(res.data.data)
        
    })
}

// 根据会员卡id查询用户信息
function getUserCardInfo(id:number){
    userManagementService.getUserCardInfo(id).then((res:any)=>{
        console.log(res.data.data);
        store.setUserCardInfo(res.data.data)
        
    })
}

//续费扣费
function renewal(change:string,illustrate:string,money:number,userCardId:number){
    userManagementService.renewal(change,illustrate,money,userCardId).then((res:any)=>{
        console.log(res.data.data);
    })
}

//更改会员卡状态
function changeUserVipCardStatus(cardStatus:number,id:number){
    userManagementService.changeUserVipCardStatus(cardStatus,id).then((res:any)=>{
        console.log(res.data.data);
        
    })
}

// 查询教练列表
function coachFindAll(){
    userManagementService.coachFindAll().then((res:any)=>{
        // console.log(res.data.data);
        coach.setCoachList(res.data.data)
    })
}


export default {
    page_vipCard,
    search_vipCardById,
    pageUser,
    userById,
    getUserCardInfoByUserId,
    searchAddressByUserId,
    getVipLevel,
    integralRuleById,
    integralRuleUpdate,
    addVipLevel,
    searchVipLevelById,
    delVipLevelById,
    changeVipLevel,
    userVipCardPageList,
    getUserCardInfo,
    renewal,
    changeUserVipCardStatus,
    coachFindAll
}